package com.bt.lms.ui.action.school_education.archives.register;

import com.bt.lms.ui.page.sys.style.BtnStyle;
import javafx.collections.ObservableList;
import javafx.event.Event;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Cursor;
import javafx.scene.Node;
import javafx.scene.control.*;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;

import java.util.ArrayList;
import java.util.List;

/**
 * 注册信息添加功能事件
 */
public class RegisterAddAction implements EventHandler {

    private VBox totalVBox;

    private Integer baseWidth = 1230;


    public RegisterAddAction(VBox vBox) {
        this.totalVBox = vBox;
    }

    @Override
    public void handle(Event event) {
        VBox vBox = new VBox();
        HBox btnBox = new HBox();
        btnBox.setPrefWidth(1230);
        btnBox.setAlignment(Pos.CENTER_RIGHT);
        btnBox.setSpacing(10);
        Insets insets1 = new Insets(10,50,10,10);
        btnBox.setPadding(insets1);
        Button saveBtn = new Button("保存");
        Button cancelBtn = new Button("取消");
        btnBox.getChildren().add(saveBtn);
        btnBox.getChildren().add(cancelBtn);
        BtnStyle.saveBtn(saveBtn);
        BtnStyle.cancelBtn(cancelBtn);
        saveBtn.setCursor(Cursor.HAND);
        cancelBtn.setCursor(Cursor.HAND);

        ObservableList<Node> children = this.totalVBox.getChildren();
        vBox.getChildren().add(btnBox);

        //保存验证按钮事件
        AddRegisterVerify addRegisterVerify = new AddRegisterVerify(totalVBox);
        saveBtn.setOnAction(addRegisterVerify);

        //注册信息的主盒子
        VBox totalHBox = new VBox();
        totalHBox.setPrefWidth(baseWidth);
        totalHBox.setSpacing(10);


        HBox enterSchoolDayBox = new HBox();
        enterSchoolDayBox.setSpacing(10);
        Label conditionLab = new Label("注册状况");
        conditionLab.setPrefWidth(baseWidth/8);
        ComboBox conditionCB = new ComboBox<>();
        conditionCB.setId("conditionCB");
        conditionCB.setPrefWidth(baseWidth/6);
        conditionCB.getItems().addAll("注册","报到","未报到");
        Label registerTimeLab = new Label("注册日期");
        registerTimeLab.setPrefWidth(baseWidth/8);
        DatePicker registerTimeDP = new DatePicker();
        registerTimeDP.setId("registerTimeDP");
        registerTimeDP.setPrefWidth(baseWidth/6);
        Label checkInTimeLab = new Label("报道日期");
        checkInTimeLab.setPrefWidth(baseWidth/8);
        DatePicker checkInTimeDP = new DatePicker();
        checkInTimeDP.setId("checkInTimeDP");
        checkInTimeDP.setPrefWidth(baseWidth/6);
        enterSchoolDayBox.getChildren().addAll(conditionLab,conditionCB,registerTimeLab,registerTimeDP,checkInTimeLab,checkInTimeDP);
        totalHBox.getChildren().add(enterSchoolDayBox);

        HBox two = new HBox();
        two.setSpacing(10);
        Label notRegisterCauseLab = new Label("未注册原因");
        notRegisterCauseLab.setPrefWidth(baseWidth/8);
        TextField notRegisterCauseTF = new TextField();
        notRegisterCauseTF.setId("notRegisterCauseTF");
        notRegisterCauseTF.setPrefWidth(baseWidth/6);
        Label notRegisterGoLab = new Label("未注册/报道去向");
        notRegisterGoLab.setPrefWidth(baseWidth/8);
        TextField notRegisterGoTF = new TextField();
        notRegisterGoTF.setId("notRegisterGoTF");
        notRegisterGoTF.setPrefWidth(baseWidth/6);
        Label vacateLab = new Label("是否请假");
        vacateLab.setPrefWidth(baseWidth/8);
        ComboBox vacateCB = new ComboBox<>();
        vacateCB.setId("vacateCB");
        vacateCB.setPrefWidth(baseWidth/6);
        vacateCB.getItems().addAll("是","否");
        two.getChildren().addAll(notRegisterCauseLab,notRegisterCauseTF,notRegisterGoLab,notRegisterGoTF,vacateLab,vacateCB);
        totalHBox.getChildren().add(two);

        HBox three = new HBox();
        three.setSpacing(10);
        Label schoolYearLab = new Label("学年(度)");
        schoolYearLab.setPrefWidth(baseWidth/8);
        TextField schoolYearTF = new TextField();
        schoolYearTF.setId("schoolYearTF");
        schoolYearTF.setPrefWidth(baseWidth/6);
        Label semesterLab = new Label("学期");
        semesterLab.setPrefWidth(baseWidth/8);
        TextField semesterTF = new TextField();
        semesterTF.setId("semesterTF");
        semesterTF.setPrefWidth(baseWidth/6);
        Label classLab = new Label("所在班级");
        classLab.setPrefWidth(baseWidth/8);
        TextField classTF = new TextField();
        classTF.setId("classTF");
        classTF.setPrefWidth(baseWidth/6);
        three.getChildren().addAll(schoolYearLab,schoolYearTF,semesterLab,semesterTF,classLab,classTF);
        totalHBox.getChildren().add(three);
        vBox.getChildren().add(totalHBox);

        children.add(vBox);

        /**
         * 取消按钮事件
         */
        cancelBtn.setOnAction(event1 -> {
            children.remove(3);
        });

    }
}
